# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $ app-text/ghostdpl/ghostdpl-9.14,v 1.1 2014/05/06 00:40:00 itspec.ru Exp $

EAPI=3

FONT_PN="urwfonts"

inherit eutils font

DESCRIPTION="GhostPCL, GhostXPS, Ghostscript and GhostPDF Interpreters"
HOMEPAGE="http://www.ghostscript.com/GhostPCL.html"
SRC_URI="http://downloads.ghostscript.com/public/ghostpdl-${PV}.tar.bz2"

LICENSE="AGPL-3"

RESTRICT="mirror"

SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="pcl xps ls tools debug doc fonts X"

DEPEND="fonts? ( media-fonts/urwfonts )
        X? ( x11-libs/libXt x11-libs/libXext )"

RDEPEND="${DEPEND}"

src_prepare() {
    if use fonts; then
        sed -e "s:/windows/fonts:"${FONTDIR}";/windows/fonts:" -i ${S}/pl/pjparse.c
        sed -e "s:/windows/fonts:"${FONTDIR}":" -i ${S}/tools/gslite/gslt_test.c
        sed -e "s:/windows/fonts:"${FONTDIR}":" -i ${S}/tools/makeromttf.py
    fi
}

src_configure() {
        econf $(use_with X x)
}

src_compile() {
    local BUILD=""

    if use debug; then
        BUILD="debug"
    else
        BUILD="product"
    fi

    if use pcl; then
        emake -j1 DESTDIR="${D}" -C main -f pcl6_gcc.mak pdl-${BUILD} || die "compile failure"
    fi

    if use xps; then
        emake -j1 DESTDIR="${D}" -C xps -f xps_gcc.mak pdl-${BUILD} || die "compile failure"
    fi

    if use ls; then
        emake -j1 DESTDIR="${D}" UNSUPPORTED=1 -C language_switch -f pspcl6_gcc.mak pdl-${BUILD} || die "compile failure"
    fi
}

src_install() {
    if use pcl; then
        dobin "${S}/main/obj/pcl6" || die "pcl6 install failed"
    fi

    if use xps; then
        dobin "${S}/xps/obj/gxps" || die "gxps install failed"
    fi

    if use ls; then
        dobin "${S}/language_switch/obj/pspcl6" || die "pspcl6 install failed"
    fi

    if use tools; then
        dobin "${S}/tools/pcl2pdf" || die "pcl2pdf install failed"
        dobin "${S}/tools/pcl2pdfwr" || die "pcl2pdfwr install failed"
    fi

    if use doc; then
        dodoc "${S}/doc/${PN}".{pdf,txt} || die "doc install failed"
    fi
}
